<template>
  <el-form-item label="注册公司" prop="company_id" :rules="[{ required: true, message: '不能为空', trigger: 'change' }]">
    <VSelect v-model="form.company_id" placeholder="请选择" :options="options.company" filterable clearable class="w-1/2" :disabled="!!form.shop_id && form.company_id"
      @change="companyChange" />
  </el-form-item>
  <div v-if="form.company.company_id" class="grid grid-cols-3 gap-3 mb-3">
    <VText title="公司名称" :value="form.company.company_name_ch" />
    <VText title="公司名称拼音" :value="form.company.company_name_py" />
    <VText title="营业执照号" :value="form.company.license_num" />
    <VText title="公司成立时间" :value="form.company.established_date" />
    <VText title="公司地址" :value="form.company.company_area_names + form.company.company_address_detail" />
    <VText title="公司地址拼音" :value="form.company.company_address_pinyin" />
    <VText title="邮编" :value="form.company.postal_code" />
    <VText title="法人姓名" :value="form.company.legal_person_name" />
    <VText title="法人身份证号" :value="form.company.legal_person_idcard" />
    <VText title="法人手机号" :value="form.company.legal_person_mobile" />
    <VText title="对公银行" :value="form.company.public_bank" />
    <VText title="银行支行" :value="form.company.bank_branch" />
    <VText title="银行卡号" :value="form.company.bank_account_num" />
  </div>
</template>

<script setup>
import XEUtils from 'xe-utils'
const props = defineProps({
  modelValue: { type: Object, default: () => ({}) },
  options: { type: Object, default: () => ({}) },
  detail: { type: Function, default: () => ({}) },
})
const emit = defineEmits(['update:modelValue'])
const form = computed({
  get() {
    return props.modelValue
  },
  set(val) {
    emit('update:modelValue', val)
  }
})

const companyChange = ({ value }) => {
  props.detail({ company_id: value }).then(res => {
    form.value.company = XEUtils.merge({
      "company_id": '',
      "company_name_ch": "",
      "company_name_py": "",
      "license_num": "",
      "established_date": "",
      "company_area_names": "",
      "company_address_detail": "",
      "company_address_pinyin": "",
      "postal_code": "",
      "legal_person_name": "",
      "legal_person_idcard": "",
      "legal_person_mobile": "",
      "public_bank": "",
      "bank_branch": "",
      "bank_account_num": ""
    }, res.data)
  })
}
</script>